<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css" />
		<link rel="stylesheet" href="../css/iconfont.css">
		<style>
			.mui-content-padded{margin:5px 0 0 0;}
			.mui-row-list span{float: left; line-height:33px; width:20%;}
			.mui-row-list select{float: left; line-height:14px; font-size:14px; margin-top:2px; margin-left: 5px;}
			.mui-btn-block{margin-bottom:0; padding:6px;}
			.mui-col-sm-12{ border-top: 1px solid #D1D1D1; width:100%; padding-top:5px; font-size:14px;}
			.mui-switch{
				border-color: #007AFF;
				background-color: #007AFF;
				border-width: 1px;
			}
			#mySwitch:before {content: '好'; color: #fff; right: 15px;}
			#mySwitch.mui-active:before {content: '不好'; color: #fff; left: 10px;}
			#mySwitch1:before {content: '无'; color: #fff; right: 15px;}
			#mySwitch1.mui-active:before {content: '有'; color: #fff; left: 15px;}
			#mySwitch2:before {content: '不需要'; color: #fff; right: 5px;}
			#mySwitch2.mui-active:before {content: '需要'; color: #fff; left: 10px;}
			#mySwitch3:before {content: '否'; color: #fff; right: 15px;}
			#mySwitch3.mui-active:before {content: '需转诊'; color: #fff; left: 5px;}
			.mui-switch:before {content: '否'; color: #fff; right: 15px;}
			.mui-switch.mui-active:before {content: '是'; color: #fff; left: 15px;}
			.mui-switch.mui-active {
				border-color: #fd933b;
				background-color: #fd933b;
			}
			.mui-ul-check{ width: 100%; margin: 0; padding: 0;}
			.mui-ul-check li{float: left; list-style-type:none; text-align: center; padding:5px; margin:2px; border:1px solid #D1D1D1;}
			.mui-ul-check li.on{ background-color:#007AFF; color:#FFFFFF; float: left; list-style-type:none; text-align: center; padding:5px; margin:2px;}	
			.mui-table-view-cell.mui-active{ display:block;}
			input{border-width:0; text-align: right; font-size:14px; line-height: 26px;}
			input[type="number"]{height:26px; padding: 0;border-width:0;margin-bottom:0;background:none;}
			.bottom_soild{border-bottom: 1px solid #DDDDDD; margin-right: 5px;}
			.submit{
				margin:0 auto 10px auto; 
				width:200px; 
				height:35px; 
				line-height: 35px; 
				background-color:#007AFF; 
				text-align: center; 
				color: #FFFFFF; 
				border-radius: 10px;
				margin-top: 10px;
			}
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">辅助检查</h1>
		</header>
		<div class="mui-conten" style="margin-top:50px;">
			<div style="margin-left:0.9rem; line-height:35px;">心理状态与指导</div>
			<ul class="mui-table-view">
				<div class="mui-row">
					<li class="mui-table-view-cell">
						<ul class="mui-ul-check" id="guide">
							<li value="335">心理状态好</li>
							<li value="434">可疑抑郁</li>
							<li value="435">心理指导</li>
							<li value="8">需转诊</li>
						</ul>
					</li>
				</div>
			</ul>
			<div style="margin-left:0.9rem; line-height:35px;">疾病预防知识教育</div>
			<ul class="mui-table-view">
				<div class="mui-row">
					<li class="mui-table-view-cell">
						<ul class="mui-ul-check" id="knowledge">
							<li value="436">疫苗接种</li>
							<li value="437">冠心病预防</li>
							<li value="438">骨质疏松预防</li>
						</ul>
					</li>
				</div>
			</ul>
			<div onclick="submit()" class="submit" >保存</div>
		</div>
		<script src="../js/mui.js"></script>
		<script src="../js/mui.picker.min.js"></script>
		<script src="../js/jquery.min-1.11.1.js"></script>
		<script src="../js/request.js"></script>
		<script type="text/javascript">
			//获取变量
			var self = localStorage.getItem("name")
			console.log(self)
			var dataold = JSON.parse(self)
			var obj = dataold.obj
			var selfdata ="";
			var listdata ="";
			mui.plusReady(function(){
				var self = plus.webview.currentWebview()
					listdata = self.data;
					visitId = self.visitdata;
					selfdata = JSON.parse(listdata)
					console.log(selfdata.ehrId)
				var date1 = new Date();
				var year1=date1.getFullYear(); 
				var month1=date1.getMonth()+1;
				var day1=date1.getDate();
				var h1=date1.getHours();
				var m1=date1.getMinutes();
				var s1=date1.getSeconds();
					month1 =(month1<10 ? "0"+month1:month1); 
					day1 =(day1<10 ? "0"+day1:day1); 
					h1 =(h1<10 ? "0"+h1:h1); 
					m1 =(m1<10 ? "0"+m1:m1); 
					s1 =(s1<10 ? "0"+s1:s1);
					createDate = (year1.toString()+'-'+month1.toString()+'-'+day1.toString()+' '+h1.toString()+':'+m1.toString()+':'+s1.toString());
					modifyDate = (year1.toString()+'-'+month1.toString()+'-'+day1.toString()+' '+h1.toString()+':'+m1.toString()+':'+s1.toString());
					ehrId = selfdata.ehrId;
				if(self.second != ""){
					first = JSON.parse(self.first);
					second = JSON.parse(self.second);
					id = first.id;
					createUser = first.createUser;
					createDate = first.createDate;
					console.log(self.second);
					for(var i=0; i<second.length; i++){
						if(second[i].questionId == 521){
							console.log("1122")
							var guideidYnarr = second[i].answer;
							if(guideidYnarr != null){
								var guideidYnarr_n = guideidYnarr.split(",");
								if(guideidYnarr_n.length != 0){
									$ ("#guide").each (function (){
										$ (this).find ('li').each (function (){
											var y = guideidYnarr_n.length-1;
											for (var i=0; i<guideidYnarr_n.length; i++) {
												if ($(this).val() == guideidYnarr_n[i]) {
							                        $(this).addClass("on");
							                    }		
											}
										})
									})	
								}
							}
						}
						if(second[i].questionId == 522){
							var knowledgeidYnarr = second[i].answer;
							if(knowledgeidYnarr != null){
								var knowledgeidYnarr_n = knowledgeidYnarr.split(",");
								if(knowledgeidYnarr_n.length != 0){
									$ ("#knowledge").each (function (){
										$ (this).find ('li').each (function (){
											var y = knowledgeidYnarr_n.length-1;
											for (var i=0; i<knowledgeidYnarr_n.length; i++) {
												if ($(this).val() == knowledgeidYnarr_n[i]) {
							                        $(this).addClass("on");
							                    }		
											}
										})
									})	
								}
							}
						}
					}
				}
			})
			//赋值
			//var id=0;
			var visitId= 0;
			var ehrId = "";
			var createUser = obj.id;
			var createDate = "";
			var updateUser = obj.id;
			var guideid = "";
			var knowledgeid = "";
			mui.init()
			
			//复选框事件
			mui('.mui-ul-check').on('tap', 'li', function(e) {
				if(!this.getAttribute('class')){
					this.classList.add('on')
				}else{
					this.classList.remove('on');
				}
			});
			//提交
			function submit(){
				//复选框
				$("#guide").find ('.on').each (function (){
					guideid += $(this).val() + ",";
				});
				//去掉最后一个逗号(如果不需要去掉，就不用写)
				if (guideid.length > 0) {
					guideid = guideid.substr(0,guideid.length - 1);
				}
				$("#knowledge").find ('.on').each (function (){
					knowledgeid += $(this).val() + ",";
				});
				//去掉最后一个逗号(如果不需要去掉，就不用写)
				if (knowledgeid.length > 0) {
					knowledgeid = knowledgeid.substr(0,knowledgeid.length - 1);
				}
				console.log(guideid)
				console.log(knowledgeid)
				var dataobj=[
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"521",
					"answerId":"0",
					"answer":guideid,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser},
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"522",
					"answerId":"0",
					"answer":knowledgeid,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser}
				]
				$.ajax({
					type: 'post',
					url:getRequestUrl.url+"/mobile/ehr/OldsterVisitAnswer/addOrUpdate",
					data:JSON.stringify(dataobj),
					dataType:"json",
					contentType : 'application/json;charset=utf-8',
					success : function(data) {
						if(data.status==1){
							alert("提交成功")
							mui.openWindow({
								url: 'follow_up_add.html', 
								id:'follow_up_add',
								extras:{
									
								}
							});
						}else{
							alert(data.message);
						}
					},
					error:function(xhr,type,errorThrown){
						
					}
				})
			}
		</script>
	</body>
</html>